package com.ctg.payroll2.util;

import java.util.List;

import net.sf.json.JSONArray;

public class PayrollUtil {
	/**
	 * 将类似与["a","b","c","d","e","f"]的字符串转换为字符串数组
	 * @param args 字符串
	 * @return 字符串数组
	 */
	public static String[] splitStringToStringArray(String args) {
		JSONArray json = JSONArray.fromObject(args);
		Object[] ss = json.toArray();
		String[] array = new String[ss.length];
		for (int i = 0; i < ss.length; i++) {
			String s = (String)ss[i];
			array[i] = s;
		}
		return array;
	}
	/**
	 * 将类似与[0,1,2,3,4,5]的字符串转换为整形数组
	 * @param args 字符串
	 * @return 整形数组
	 */
	public static int[] splitStringToIntArray(String args) {
		JSONArray json = JSONArray.fromObject(args);
		Object[] ss = json.toArray();
		int[] array = new int[ss.length];
		for (int i = 0; i < ss.length; i++) {
			Integer s = (Integer)ss[i];
			array[i] = s;
		}
		return array;
	}
	
	/**
	 * 将类似与[0,1,2,3,4,5]的字符串转换为整形数组
	 * @param args 字符串
	 * @return 整形数组
	 */
	public static long[] splitStringToLongArray(String args) {
		JSONArray json = JSONArray.fromObject(args);
		Object[] ss = json.toArray();
		long[] array = new long[ss.length];
		for (int i = 0; i < ss.length; i++) {
			Long s = (Long)ss[i];
			array[i] = s;
		}
		return array;
	}
	
	public static void main(String[] args) {
	}
	
	public static String getStringForIbatisByList(List<String> list){
		StringBuffer sb = new StringBuffer();
		for (String s : list) {
			sb.append("'").append(s).append("',");
		}
		return sb.substring(0, sb.length()-1);
	}
	
	public static String[] getStringArrayByList(List<String> list){
		String[]  str = new String[list.size()];
		for (int i = 0; i < str.length; i++) {
			str[i] = list.get(i);
		}
		return str;
	}
	
	public static String getJsonStringByList(List<String> list){
		if (list==null||list.size()==0) {
			return "[]";
		}
		StringBuffer sb = new StringBuffer();
		sb.append("[");
		for (int i = 0; i < list.size(); i++) {
			String s = list.get(i);
			sb.append("'"+s+"',");
		}
		String str = sb.substring(0, sb.length()-1)+"]";
		return str;
	}
}
